package io.gitee.hefren.hhconfig.client.service;

import io.gitee.hefren.hhconfig.client.beans.ConfigsMeta;
import io.gitee.hefren.hhconfig.client.repository.HhConfigRepository;
import io.gitee.hefren.hhconfig.client.service.impl.HhConfigServiceImpl;
import org.springframework.context.ApplicationContext;

import java.util.Map;

public interface HhConfigService extends ChangeListener{

    static HhConfigService getDefault(ApplicationContext applicationContext, ConfigsMeta configsMeta) {
        HhConfigRepository hhConfigRepository = HhConfigRepository.getDefault(configsMeta);
        Map<String, String> conf = hhConfigRepository.findConfigs();
        HhConfigService hhConfigService = new HhConfigServiceImpl(applicationContext, conf);
        hhConfigRepository.addChangeListener(hhConfigService);
        return hhConfigService;
    }

    String[] getPropertyNames();

    String getProperty(String name);
}
